{config_load file="global.conf"}
{config_load file="_order_service.conf" section="`$lang`"}

{*
{$Staff->getSubscrData()}
{$Staff->subscrDaysLeft}
{$Staff->wasOnTrial()}
*}


{if $lang=="en"}
	{assign var="curr_pre" value=#_order_service__labelCurrency#}
	{assign var="curr_post" value=""}
{else}
	{assign var="curr_pre" value=#_order_service__labelCurrency#}
	{assign var="curr_post" value=""}
{/if}


{*if $smarty.get.s=='' && !$Staff->Login()}
    <script type="text/javascript">
        window.location="/{$lang}/free-trial.html";
     </script>
{/if}
{if !$smarty.get.s && $Staff->Login()}
 <script type="text/javascript">
        window.location="/{$lang}/subscribe.html";
 </script>
{/if*}


{$Order->setUser($Staff->UserID())}
{$Order->setSubscr($Staff->checkSubscribed())}
{$Order->setTrial($Staff->isTrialFinished())}


<script type="text/javascript" language="JavaScript">
{literal}


/////////////// xajax ///////////////////////////////////////
var UserID = 0;
var DiscountSize = 0;
var DiscountStatus = false;

function checkDiscount(userID) {
	UserID = userID;
	xajax.loadingFunction = emptyfunc;
   	xajax.doneLoadingFunction = afterXajaxLoaded;
   	xajax_getDiscount(xajax.getFormValues("frm_discount"),userID,"check");
}

// mark discount as used and submit form
function useDiscount(userID) {
	xajax.loadingFunction = emptyfunc;
   	xajax.doneLoadingFunction = paymentFormSubmit;
   	xajax_getDiscount(xajax.getFormValues("frm_discount"),userID,"use");
}

function emptyfunc() {}
function emptyfunc1() {alert("d1")}


//addLoadEvent(checkDiscount);


function disableDiscount(){
	document.getElementById('discount_code').disabled = true;
	document.getElementById('discount_submit').disabled = true;
}

function calculateDiscount(){
	 //set starting values before calculating
	 //added to prevent multiple clicking on cancel button
	document.paypalForm.elements['a3'].value = startPP;
	document.webmoneyForm.elements['LMI_PAYMENT_AMOUNT'].value = startWM;

	var discount = document.getElementById('discount_size').value;
	var pricePP = document.paypalForm.elements['a3'].value;
	var priceWM = document.webmoneyForm.elements['LMI_PAYMENT_AMOUNT'].value;

	if (discount>0){
		//discount for paypal
		document.paypalForm.elements['a3'].value = pricePP - parseInt(pricePP * (discount/100));
		//discount for webmoney
		document.webmoneyForm.elements['LMI_PAYMENT_AMOUNT'].value = priceWM - parseInt(priceWM * (discount/100));
	}
}


//////////////////// discount /////////////////////////////////////

{/literal}
</script>
<input type="hidden" value="0" id="discount_size" />
<input type="hidden" value="" id="discount_message" />

<!--
{*//////////////////  special offer banner  ////////////////*}
{*if $lang=="en"*}
 <table class="bannerTable">
{*else*}
 {*<table class="bannerTableClear"> *}
{*/if*}
 <tr>
	<td align="left" valign="top">

	 <table border="0" width="600" >
 		<tr>
			<td width="155" height="27" >&nbsp;</td>
			<td width="300" colspan="2" class="banGraySmall"><nobr><b>{#_order_service__labelSpecOffer#}{*SPECIAL OFFER*}</b></nobr></td>
			<td colspan="2" align="right" style="font-size: 10pt" class="banGraySmall"><nobr><b>{#_order_service__labelSpecOfferEnds#}&nbsp;&nbsp;</b></nobr></td>
			<!--<td></td>
			<td></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td colspan="3" class="banMiddle1" height="72" valign="middle"><span class="banMiddle2">{#_order_service__labelSignUp#}{*Sign up today and get*}</span><br><span class="banGreenBig" style="padding-top: 0px">{#_order_service__label2Month#}{*two months*}</span> {#_order_service__labelPrice#}{*for the price of*} <span class="banGreenBig">{#_order_service__labelOne#}{*one*}</span></td>
		</tr>

		<tr>
			<td>&nbsp;</td>
			<td valign="top" width="155" class="banWhite"><nobr><b>{#_order_service__labelStndartRate#}{*Standard rate:*}</b></nobr><br><nobr><span class="banNum"><span class="banTextThrough">{#_order_service__labelStndartRateValue#}</span></span> <span class="banThrough">{#_order_service__labelPerMonth#}{*per month*}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nobr></td>
			<td valign="top"  class="banWhite"><nobr><b>{#_order_service__labelDiscount#}{*Discounted rate:*}</b></nobr><br><nobr><span class="banGreenNum">{#_order_service__labelDiscountedRateValue#}</span><span class="banGreenSmall">&nbsp; <b>{#_order_service__labelPer2Month#} {*per 2 months*}</b></span></nobr></td>
			<td></td>
		</tr>
 	</table>

	</td>
 </tr>
 </table>
 -->
 <!--<p class="redColor"><b>{#_order_service__labelSpecOfferEnds#}</b></p>-->
<br>

{*//////////////////  Features  ////////////////*}

   <h3 style="margin-bottom: 5px; margin-top: 0px">{#_order_service__labelReceive#}{*All Subscribers Receive:*}</h3>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 0px"><tr><td class="dottedLine"><img src="{#images_dir#}/spacer.gif" /></td></tr></table>

   <table width="90%">
  	<tr>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top" width="51%">{#_order_service__item1Receive#}{*IntelliForex Software Package*}</td>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top" width="45%">{#_order_service__item6Receive#}{*MM*}</td>
	</tr><tr>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top">{#_order_service__item3Receive#} <a href="/{$lang}/forex-alerts-coverage.html">{#_order_service__item31Receive#}</a>{*E-mail Alerts SMS*}</td>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top">{#_order_service__item2Receive#}{*Dashboard*}</td>
	</tr><tr>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top"><span class="new">MetaTrader4 <a href="/{$lang}/auto-trading-signup.html">{#_order_service__item7Receive#}</a>{*MetaTrader4 Auto-Trading Bridge*}</span></td>
		<td valign="top"><img src="{#images_dir#}/arrow_orange.gif" vspace="2" align="top" />&nbsp;</td><td valign="top">{#_order_service__item4Receive#}{*Real-Time Forex Charts*}</td>
	</tr>
	</table>
<!--
	<br>
     <span>{#_order_service__msgAttention#}</span>
-->
    <br /><br />

	 
{assign var=servicesData value=$Order->getServicesData()}

{*//////////////////  systems  ////////////////*}

<div style="display:none;">
	<script>var allSystemsID=0;</script>
	<input name="system_cb_0" id="system_cb_0" type="checkbox" value="0">
</div>

<table width="100%"  cellpadding="1" cellspacing="1">	
<tr>
	<td class="theader" width="5%">&nbsp;</td>
	<td class="theader">{#_order_service__msgSystems#}</td>
	<td class="theader" width="32%">{#_order_service__msgPPM#}</td>
	<td class="theader" width="32%">{#_order_service__msgNotes#}</td>
</tr>

{assign var=rowCounter value=1}	
{foreach key="itr" from=$Order->getSystems() item=system}
<tr {if $rowCounter%2!=0} class="darkRow" {/if}>
	<td>
		<div><input name="system_cb_{$rowCounter}" id="system_cb_{$rowCounter}" {if $itr==0}checked="checked"{/if} 
		type="checkbox" value="{$system.service_system}" 
		onClick="javascript:setPrices({if $system.service_system==0}{$rowCounter}{else}false{/if} );"></div>
		{if $system.service_system==0} <script>var allSystemsID={$rowCounter};</script> {/if}
	</td>
	<td {if $system.service_system==0}class="justBold"{/if}>
	{if $system.service_system!=0}
		<a href="/{$lang}/performance-calculator/system/{$system.service_system}/">{$system.Name}</a>
	{else}{$system.Name}{/if}</td>
	<td {if $system.service_system==0}class="justBold"{/if}>${$system.service_price}</td>
	<td {if $system.service_system==0}class="justBold"{/if}>
		{if $system.isSignal==0 && $system.isAT==1}{#_order_service__msgATonly#}{/if}
		{if $system.service_system==0}{#_order_service__msgSpecialOffer#}{/if}
		{assign var=sysid value=$system.service_system}
		{foreach key="periodKey" from=$Order->periodsPricesArray.$sysid item=sysPrice}
			<input type="hidden" value="{$sysPrice}" id="system_price_{$rowCounter}_{$periodKey}" />
			{if $system.service_system==0}<script>var offerPeriod = "{$periodKey}";</script>{/if}
		{/foreach}
		<input type="hidden" value="{$system.service_system}" id="system_id_{$rowCounter}" />
		<input type="hidden" value="{$system.Name}" id="system_name_{$rowCounter}" />
	</td>
</tr>
<!-- {$rowCounter++} -->
{/foreach}
</table><br />

{*//////////////////  periods  ////////////////*}

<!--{$Order->getServicesData()}-->
<table width="100%"  cellpadding="1" cellspacing="1">
<tr>
	<td class="theader" width="5%">&nbsp;</td>
	<td class="theader">{#_order_service__msgPeriods#}</td>
	<td class="theader" width="32%">{#_order_service__msgPrices#}</td>
	<td class="theader" width="32%">&nbsp;{*#_order_service__msgSave#*}</td>
</tr>
{assign var=rowCounter value=1}	
{foreach key="itr" from=$Order->periodsArray item=period}
<tr {if $rowCounter%2!=0} class="darkRow" {/if}>
	<td>
		<div><input name="periods" type="radio" value="paypal" id="period_rb_{$rowCounter}" {if $rowCounter==1}checked="checked"{/if}  
		onClick="javascript:setSubTotal({$rowCounter});"></div>
	</td>
	<td>{$period.time}
		{if $period.time_units=="M"}
			{if $period.time==1}
				{assign var=periodSuffix value=$smarty.config._order_service__msgMonth}
				{#_order_service__msgMonth#}{*month*}
			{elseif $period.time>1 && $period.time<5}
				{assign var=periodSuffix value=$smarty.config._order_service__msgMonth2}
				{#_order_service__msgMonth2#}{*months*}
			{else}
				{assign var=periodSuffix value=$smarty.config._order_service__msgMonths}
				{#_order_service__msgMonths#}{*months*}
			{/if}
		{elseif $period.time_units=="D"}
			{assign var=periodSuffix value=$smarty.config._order_service__msgDays}
			{#_order_service__msgDays#}{*days*} Trial
		{/if}
	</td>
	<td >
		<span id="period_price_{$rowCounter}">&nbsp;</span>
		<input type="hidden" value="" id="period_price1_{$rowCounter}" />
	</td>
	<td >
		<span id="period_save_{$rowCounter}">&nbsp;</span>
		<input type="hidden" value="{$period.time}" id="period_time_{$rowCounter}" />
		<input type="hidden" value="{$period.time_units}" id="period_units_{$rowCounter}" />
		<input type="hidden" value="{$period.id}" id="period_key_{$rowCounter}" />
		<input type="hidden" value="{$period.time} {$periodSuffix}" id="period_text_{$rowCounter}" />
		<input type="hidden" value="{$period.days}" id="period_days_{$rowCounter}" />
		<input type="hidden" value="{$period.invoice}" id="period_invoice_{$rowCounter}" />
	</td>
</tr>
<!-- {$rowCounter++} -->
{/foreach}
<tr>
	<td class="theader">&nbsp;</td>
	<td class="theader"><span style="font-size: 12pt">{#_order_service__msgSubtotal#}</span></td>
	<td class="theader"><span style="font-size: 12pt">$<span id="period_subtotal">&nbsp;</span></span></td>
	<td class="theader">&nbsp;</td>
</tr>

</table>


<input type="hidden" value="" id="final_price" />
<input type="hidden" value="" id="final_name" />
<input type="hidden" value="" id="final_invoice" />
{********************************************************************
<table width="100%"  cellpadding="1" cellspacing="1">	
<tr>
		<td class="theader" colspan="2">&nbsp;{#_order_service__msgSubscription#}</td>
		<td  class="theader">{#_order_service__msgRate#}</td>

		<td style="display:none"

		 class="theader">{#_order_service__msgDiscountRate#}</td>
		<td class="theader"><nobr>{#_order_service__msgPerformance#} <a href="/{$lang}/performance-guarantee.html">{#_order_service__linkGuarantee#}</a></nobr></td>
</tr>	
  </table>
***************************************************************}

	 <div
	 {if $lang=="en"}
	 style="display: none;"
	 {/if}
	 >
	 {include file="_form_discount.tpl"}
	 </div><br>


{*//////////////////  Payment methods  ////////////////*}

<table border="0" width="100%" cellpadding="1" cellspacing="1">
<tr>
	<td class="theader" colspan="3">&nbsp;{#_order_service__msgPaymentMethod#}{*Payment method*}</td>
</tr>
<tr>
	<td class="darkRow" width="40" height="45">
	<input name="method" type="radio" value="paypalForm" checked onClick="javascript:setPaymentMethod();"></td>
	<td width="160" class="darkRow"><img src="{#images_dir#}/pay/logo_ccVisa.gif" align="middle" /> <img src="{#images_dir#}/pay/logo_ccMC.gif" align="middle" /> <img src="{#images_dir#}/paypal.gif" align="middle" />
	</td>
	<td class="darkRow">{#_order_service__msgPayPal#}{*Pay using your PayPal account or credit card*} &nbsp;&nbsp;&nbsp;</td>
</tr>
<tr>
	<td height="45">
	<input name="method" type="radio" value="webmoneyForm" onClick="javascript:setPaymentMethod();">&nbsp;</td>
	<td><img src="{#images_dir#}/webmoney.gif" align="middle" /></td>
	<td>{#_order_service__msgWebmoney#}{*use webmoney*}</td>
</tr>
<tr style="display: none;">
	<td  class="darkRow" height="45">
	<input class="darkRow" name="method" type="radio" value="egoldForm" onClick="javascript:setPaymentMethod();">&nbsp;</td>
	<td class="darkRow"><img src="{#images_dir#}/egold.gif" align="middle" /></td>
	<td class="darkRow">{#_order_service__msgEgold#}</td>
</tr>
<tr style="display: none;" height="45">
	<td class="darkRow">
	<input name="method" type="radio" value="BB_BuyButtonForm" onClick="javascript:setPaymentMethod();">&nbsp;</td>
	<td class="darkRow"><img src="{#images_dir#}/google.gif" align="middle" /></td>
	<td class="darkRow">{#_order_service__msgGoogleCheckOut#}{*Pay by credit card using Google Checkout*}</td>
</tr>
<tr style="display: none;" height="45">
	<td class="darkRow" height="45">
	<input name="method" type="radio" value="chequeForm" onClick="javascript:setPaymentMethod();">&nbsp;</td>
	<td class="darkRow"></td>
	<td class="darkRow" align="center">{#_order_service__msgCheck#}{*Send a check or money order*}</td>
</tr>
</table>


{*//////////////////  agreements  ////////////////*}

<table border="0" width="100%" cellpadding="1" cellspacing="1">
<tr>
	<td width="40"><br><input name="agreement" id="agreement" type="checkbox" value="ON">&nbsp;</td>
	<td><br>{#_order_service__msgAgree#} <a target="_blank" href="/{$lang}/end-user-agreement.html">{#_order_service__msgAgreement#}{*End-User License and Subscription Agreement*}</a> {#_order_service__msgRisk#}{*and I fully understand the risks involved with Forex Trading as outlined in the*} <a target="_blank" href="/{$lang}/risk-disclaimer.html">{#_order_service__linkRisk#}{*Risk Disclaimer*}</a>
	</td>

</tr>
</table>
<br>

<input type="hidden" id="authorized" value="{$Staff->Login()}">
<input type="hidden" id="isTrial" value="{$Staff->isTrialFinished()}">
<input type="hidden" id="isCap" value="{$smarty.get.cap}">
<input type="hidden" id="isMethod" value="{$smarty.get.method}">
<div id="formCode">
{foreach from=$Order->inputsArr item=method}
{$method}
{/foreach}
<script id="pap_x2s6df8d" src="http://partner.intelli4x.com/scripts/salejs.php" type="text/javascript">
</script>
<script type="text/javascript">
PostAffTracker.setAppendValuesToField('||');
PostAffTracker.writeCookieToCustomField('pap_dx8vc2s5');
</script>
</div>
<div id="submitPayment">
	<input type="button" class="button" style="width: 150px" value="{#_order_service__btnContinue#}{*Continue*}" name="formSubmit" onclick="javascript:formSubmit('pay')" />
</div>
<div id="submitTrial">
	<input type="button" class="button" style="width: 150px" value="{#_order_service__btnContinue#}{*Continue*}" name="formSubmit" onclick="javascript:formSubmit('try')" />
</div>
<div id="submitUnauthorized">
	<input type="button" class="button" style="width: 150px" value="{#_order_service__btnContinue#}{*Continue*}" name="formSubmit" onclick="javascript:formSubmit('auth')" />
</div>

<center><nobr><img src="{#images_dir#}/pay/logo_ccVisa.gif" />
<img src="{#images_dir#}/pay/logo_ccMC.gif" />
<img src="{#images_dir#}/pay/logo_ccAmex.gif" />
<img src="{#images_dir#}/pay/logo_ccDiscover.gif" />
<img src="{#images_dir#}/pay/PayPal_mark_37x23.gif" />
<img src="{#images_dir#}/pay/logo_wm.gif" />
<img style="display:none" src="{#images_dir#}/pay/logo_egold.gif" /></nobr></center>
<br>


<script type="text/javascript">
 {literal}
  var subMenuPage;
  var GETcap = document.getElementById("isCap").value;
  var GETmethod = document.getElementById("isMethod").value;
  var selectedService;
  var paymentMethod;
  var loggedIn = false;
  var isTrial = false;
  var startPP;
  var startWM;
  var currentSystem;
  var currentPeriod = 1;
  var selectedSystems = new Array();
  var isAllSystemsChacked = false;
  
  if (document.getElementById("authorized").value!="") loggedIn = true;
  if (document.getElementById("isTrial").value=="") isTrial = true;

function paymentFormSubmit(){
	document.getElementById(paymentMethod).submit();
}

function afterXajaxLoaded(){
	//if(document.getElementById("discount_message").value)
	window.setTimeout("processDiscount();",200)
}

function processDiscount(){
	calculateDiscount();
 	if(confirm(document.getElementById("discount_message").value)) {
  		paymentFormSubmit();
    	return true;
  	} else {
   		return false;
   	}
}


function formSubmit(butType){
	//if(!loggedIn) alert("Please Sign-Up first or Sign-In if you have already Signed-Up.");
  	if (butType=="pay") {
	  	if(!document.getElementById('agreement').checked){
		 {/literal}
	      alert("{#_order_service__msgMustAgree#}{*You must agree to the Terms and Conditions of End-User License and Subscription Agreement.*}");
		  {literal}
	      return false;
	   	}
		
		// if no systems selected
		if (selectedSystems.length<1) {
			{/literal}
				alert("{#_order_service__msgSelectSystem#}");
			{literal}
			return false;
		}

        if(document.getElementById("discount_code").value!=""){
        	checkDiscount({/literal}{$Staff->UserID()}{literal});
        } else {
        	paymentFormSubmit();
        }

   		return true;
	} else {
        //window.location="/index.php?p=rates&s="+subMenuPage+"&cap="+selectedService+"&method="+selectedMethod;
		window.location="/en/login.html";
	}
 }


function processPayment(){
	//if(!loggedIn) alert("Please Sign-Up first or Sign-In if you have already Signed-Up.");
	if(GETcap!="" && GETmethod!="") {
		document.getElementsByName('service')[GETcap].checked = true;
		document.getElementsByName('method')[GETmethod].checked = true;
		//setSubscrparams();
		setPaymentMethod();
		paymentFormSubmit();
	}
 }


  function trialLink(lang){
  	//if(loggedIn && isTrial) alert('You are already on a Free Trial.');
	//else if(loggedIn && !isTrial) alert('Your Free Trial has finished. Please Subscribe.');
	window.location = "/"+lang+"/free-trial.html";
 }

 function  displaySubmitButton(butType){
 	 if (loggedIn) {
 	 		if(butType=="pay"){
               	document.getElementById("submitPayment").style.display = "block";
	      		document.getElementById("submitTrial").style.display = "none";
 	 		}
 	 		else {
 	 			document.getElementById("submitPayment").style.display = "none";
	      		document.getElementById("submitTrial").style.display = "block";
	      		subMenuPage = "status";
 	 		}
	      document.getElementById("submitUnauthorized").style.display = "none";
	}
	else {

		document.getElementById("submitUnauthorized").style.display = "block";
		document.getElementById("submitPayment").style.display = "none";
	 	document.getElementById("submitTrial").style.display = "none";
	 	subMenuPage = "signin"
	}
 }

 function setSubscrparams(){
  	var serviceID;

			displaySubmitButton("pay");

			// set PayPal params
			startPP = document.getElementById('final_price').value;
			//document.paypalForm.elements['a3'].value = document.getElementById('price'+i).value;
			//document.paypalForm.elements['p3'].value = document.getElementById('time'+i).value;
			//document.paypalForm.elements['t3'].value = document.getElementById('units'+i).value;
			document.paypalForm.elements['amount'].value = document.getElementById('final_price').value;
			document.paypalForm.elements['item_name'].value = document.getElementById('final_name').value;
			document.paypalForm.elements['invoice'].value = document.getElementById('final_invoice').value;

			// set Webmoney params
			startWM = document.getElementById('final_price').value
			document.webmoneyForm.elements['LMI_PAYMENT_AMOUNT'].value = document.getElementById('final_price').value;
			document.webmoneyForm.elements['LMI_PAYMENT_DESC'].value = document.getElementById('final_name').value;
			document.webmoneyForm.elements['invoice'].value = document.getElementById('final_invoice').value;


  	//alert(document.paypalForm.elements['amount'].value+" "+document.paypalForm.elements['item_name'].value+" "+document.paypalForm.elements['invoice'].value)
}

/* 
 function setSubscrparams1(){
  	var serviceID;
  	for (var i=0;i<document.getElementsByName('service').length;i++){
  		if(document.getElementsByName('service')[i].checked){
			displaySubmitButton("pay");

			// set PayPal params
			startPP = document.getElementById('price'+i).value;
			//document.paypalForm.elements['a3'].value = document.getElementById('price'+i).value;
			//document.paypalForm.elements['p3'].value = document.getElementById('time'+i).value;
			//document.paypalForm.elements['t3'].value = document.getElementById('units'+i).value;
			document.paypalForm.elements['amount'].value = document.getElementById('price'+i).value;
			document.paypalForm.elements['item_name'].value = document.getElementById('name'+i).value;
			document.paypalForm.elements['invoice'].value = document.getElementById('invoice'+i).value;

			// set Webmoney params
			startWM = document.getElementById('discount'+i).value
			document.webmoneyForm.elements['LMI_PAYMENT_AMOUNT'].value = document.getElementById('discount'+i).value;
			document.webmoneyForm.elements['LMI_PAYMENT_DESC'].value = document.getElementById('name'+i).value;
			document.webmoneyForm.elements['invoice'].value = document.getElementById('invoice'+i).value;

			// set Egold params
			startWM = document.getElementById('price'+i).value;
			document.egoldForm.elements['PAYMENT_AMOUNT'].value = document.getElementById('price'+i).value;
			document.egoldForm.elements['SUGGESTED_MEMO'].value = document.getElementById('name'+i).value;
			document.egoldForm.elements['invoice'].value = document.getElementById('invoice'+i).value;

			// set Egold params
			startCG = document.getElementById('price'+i).value;
			document.BB_BuyButtonForm.elements['item_price_1'].value = document.getElementById('price'+i).value;
			document.BB_BuyButtonForm.elements['item_name_1'].value = document.getElementById('name'+i).value;
			document.BB_BuyButtonForm.elements['item_description_1'].value = document.getElementById('name'+i).value+" | "+document.getElementById('invoice'+i).value;
			document.BB_BuyButtonForm.elements['shopping-cart_items_item-1_unit-invoice'].value = document.getElementById('invoice'+i).value;

			selectedService = i; //set selected service var for not logged in users
        }
  	}
  	//alert(document.paypalForm.elements['a3'].value+" "+document.paypalForm.elements['p3'].value+" "+document.paypalForm.elements['invoice'].value+" "+document.webmoneyForm.elements['invoice'].value)
 }
*/

 function setPaymentMethod(){
  	for (var i=0;i<document.getElementsByName('method').length;i++){
  		if(document.getElementsByName('method')[i].checked){
            paymentMethod = document.getElementsByName('method')[i].value;
            selectedMethod = i;
        }
  	}

 }

////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function setPrices(isAllSystems){
	var ctrp=1;
	var ctrp1=1;
	var ctrs1=1;
	var totalSystems=0;
	var totalPrice=0;
	var totalSave=0;
	var totalSavePercent=0;
	var dicount2 = 0.2 //20%
	var dicount3 = 0.35 //20%
	var itemPeriod = "1m";
	
	//empty array before iterating through selected systems
	selectedSystems = new Array();
	sscntr = 0;
	
	//check if All Systems checkbox were clicked
	allSystemsClick(isAllSystems);
	
	// count systems selected
	while ( document.getElementById('system_cb_'+ctrs1) ){
		if (isAllSystemsChacked) {
			if (document.getElementById('system_id_'+ctrs1).value!=0) {
				selectedSystems[sscntr] = document.getElementById('system_id_'+ctrs1).value;
				sscntr++;
				//alert(selectedSystems);
			} 
		} else if (document.getElementById('system_cb_'+ctrs1).checked) {
				selectedSystems[sscntr] = document.getElementById('system_id_'+ctrs1).value;
				sscntr++;
				//alert(selectedSystems);
		}
		
		ctrs1++;
	}
	

	// calculate total prices and saves
	while ( document.getElementById('period_rb_'+ctrp) ){
		var totalPrice=0;
		var ctrs=1;
		var totalSystemsCounted = false;
		var totalPriceNormal;
		var price1Month = 0;
		var currentSystemCount = 0;
		
		while ( document.getElementById('system_cb_'+ctrs) ){
			var pkey = pkey0 = document.getElementById('period_key_'+ctrp).value;
			var monthCount=0;
			if (document.getElementById('period_units_'+ctrp).value=="M")
				monthCount = document.getElementById('period_time_'+ctrp).value;
			
			if (document.getElementById('system_cb_'+ctrs).checked) {
				currentSystemCount++;
			
				// if SPECIAL OFFER selected use only one period set for it
				if (isAllSystemsChacked) {
					itemPeriod = offerPeriod;
					pkey = offerPeriod;
				} else document.getElementById('period_rb_'+ctrp).disabled = false;
			
				totalPrice0 = totalPrice + parseFloat(document.getElementById('system_price_'+ctrs+'_'+pkey).value);
				totalPriceNormal = parseFloat(totalPrice0);
				
				
				//alert (totalPriceNormal)
				
				if (selectedSystems.length == currentSystemCount) {
					if (selectedSystems.length>=3 && !isAllSystemsChacked) totalPrice0 = totalPrice0 * (1-dicount3);
					else if (selectedSystems.length==2 && !isAllSystemsChacked) totalPrice0 = totalPrice0 * (1-dicount2);
				}
				
				totalPrice = Math.round (totalPrice0 * 100) / 100 ;
				
				price1Month = price1Month + parseFloat(document.getElementById('system_price_'+ctrs+'_'+itemPeriod).value);
				var priceMonth = totalPrice / monthCount;
				
				
				totalSave = Math.round ((priceMonth) * 100) / 100;
				totalSavePercent = Math.round(((price1Month - priceMonth) / price1Month) * 100);
				
				
			}
			
			ctrs++;
		}
		
		var saveText = "";
		var currSign = "$";
		if (totalSavePercent>0) var saveText = "only $"+totalSave.toFixed(2)+"/mo <b>SAVE "+totalSavePercent+"%</b>";
		totalPrice = totalPrice.toFixed(2);
		
		// if SPECIAL OFFER selected use only one period set for it
		if (isAllSystemsChacked && pkey0 != offerPeriod) {
			saveText = "";
			totalPrice = "";
			currSign = "";
		}
		 
		document.getElementById('period_price_'+ctrp).innerHTML = currSign + totalPrice;
		document.getElementById('period_price1_'+ctrp).value = totalPrice;
		document.getElementById('period_save_'+ctrp).innerHTML = saveText;
		ctrp++;
	}
	
	setSubTotal(false);

}

function allSystemsClick(isAllSystems){
	var ctrs=1;
	var ctrp=1;

	if (isAllSystems && document.getElementById('system_cb_' + isAllSystems).checked) {
	
		while ( document.getElementById('period_rb_'+ctrp) ){
			if (document.getElementById('period_key_'+ctrp).value == offerPeriod) 
				document.getElementById('period_rb_'+ctrp).checked = true;
			else document.getElementById('period_rb_'+ctrp).disabled = true;
			ctrp++;
		}
		while ( document.getElementById('system_cb_'+ctrs) ){
			document.getElementById('system_cb_'+ctrs).checked = false;
			document.getElementById('system_cb_'+isAllSystems).checked = true;
			isAllSystemsChacked = true;
		ctrs++;
		}
	} else {
		document.getElementById('system_cb_'+allSystemsID).checked = false;
		isAllSystemsChacked = false;
	}

}

function setSubTotal(periodID){
	if (!periodID) {
		periodID = currentPeriod
	} else currentPeriod = periodID;
	document.getElementById('period_subtotal').innerHTML = document.getElementById('period_price1_'+ periodID).value;
	
	setFinalInvoiceData (	document.getElementById('period_price1_'+ periodID).value, 
							document.getElementById('period_text_'+ periodID).value,
							document.getElementById('period_days_'+ periodID).value,
							document.getElementById('period_invoice_'+ periodID).value )
							
	setSubscrparams();
}

function setFinalInvoiceData(fPrice, fPeriod, fDays, fInvoice){
	
	
	{/literal}
	var fName = "{#_order_service__msgSignalsSubscrName#} "+"("+ fPeriod +")";
	{literal}
	
	var fSystems = "";
	for (var i=0; i<selectedSystems.length; i++) {
		fSystems += selectedSystems[i];
		fSystems += "%"+fDays;
		if (i != (selectedSystems.length-1)) fSystems += "-"
	}

	document.getElementById('final_price').value = fPrice;
	document.getElementById('final_name').value = fName;
	document.getElementById('final_invoice').value = fInvoice + fSystems;
}
 
 


displaySubmitButton("pay");
setPrices();
setSubTotal(false);
setPaymentMethod();
//processPayment();

 {/literal}
 </script>

{$Order->setUser($Staff->UserID())}
